package com.best.onegous.details;

import org.json.JSONException;
import org.json.JSONObject;

import com.best.onegous.BaseActivity;
import com.best.onegous.R;
import com.best.onegous.agreement.ApiInterface;
import com.best.onegous.agreement.Apps;
import com.best.onegous.agreement.Common;
import com.best.onegous.http.BusinessResponse;
import com.best.onegous.http.HttpClients;
import com.loopj.android.http.RequestParams;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;

public class Setting  extends BaseActivity implements OnClickListener,BusinessResponse{
	private Button tuichu;
	private HttpClients httpclient;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setThem(R.layout.setting_activity);
		findViewById(R.id.back).setOnClickListener(this);
		
		if (!"".equals(Common.code_id)) {
			tuichu = (Button) findViewById(R.id.tuichu);
			tuichu.setVisibility(View.VISIBLE);
			tuichu.setOnClickListener(this);
			Animation anim=AnimationUtils.loadAnimation(this, R.anim.tuichu);
			anim.setFillAfter(true);
			tuichu.startAnimation(anim);
			
		}
		httpclient = new HttpClients(this);
		httpclient.addResponseListener(this);
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back:
			 finish();
			break;
		case R.id.tuichu:
			RequestParams params = new RequestParams();
			params.add("user_id", Common.user_id);
			params.add("code_id", Common.code_id);
			httpclient.httpclient(ApiInterface.TUICHUDENGLU, params, true);
			break;


		}
	}
	@Override
	public void OnMessageResponse(String url, JSONObject jo)
			throws JSONException {
		if (null != jo) {
			if (url.equals(ApiInterface.TUICHUDENGLU)) {
				Apps.editor.putString("code_id", "");
				Apps.editor.putString("user_id", "");
				Apps.editor.commit();
				Common.code_id = "";
				Common.user_id ="";
				Animation anim=AnimationUtils.loadAnimation(this, R.anim.tuichus);
				anim.setFillAfter(true);
				anim.setAnimationListener(new AnimationListener() {
					
					@Override
					public void onAnimationStart(Animation animation) {
						// TODO Auto-generated method stub
						
					}
					
					@Override
					public void onAnimationRepeat(Animation animation) {
						// TODO Auto-generated method stub
						
					}
					
					@Override
					public void onAnimationEnd(Animation animation) {
						// TODO Auto-generated method stub
						tuichu.setVisibility(View.GONE);
					}
				});
				tuichu.startAnimation(anim);
				toast("退出成功！");
				
			}
		}
	}
}
